/* 
 * Copyright (C) 2010---2012 星星(wuweixing)<349446658@qq.com>
 * 
 * This file is part of Wabacus 
 * 
 * Wabacus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.wabacus.system.tags;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wabacus.system.assistant.TagAssistant;

public class DataImportTag extends BodyTagSupport
{
    private static final long serialVersionUID=2884967750630773439L;

    private final static Log log=LogFactory.getLog(DataImportTag.class);

    private String ref;

    private String dataimportinitsize;//初始大小，可配置值包括min/max/normal，分别表示最大化、最小化、正常窗口大小（即上面pagewidth/pageheight配置的大小）
    
    private String dataimportmaxbtn;
    
    private String dataimportminbtn;
    
    private String dataimportwidth;

    private String dataimportheight;//数据文件上传窗口的高度
    
    public String getRef()
    {
        return ref;
    }

    public void setRef(String ref)
    {
        this.ref=ref;
    }

    public void setDataimportinitsize(String dataimportinitsize)
    {
        this.dataimportinitsize=dataimportinitsize;
    }

    public void setDataimportmaxbtn(String dataimportmaxbtn)
    {
        this.dataimportmaxbtn=dataimportmaxbtn;
    }

    public void setDataimportminbtn(String dataimportminbtn)
    {
        this.dataimportminbtn=dataimportminbtn;
    }

    public String getDataimportwidth()
    {
        return dataimportwidth;
    }

    public void setDataimportwidth(String dataimportwidth)
    {
        this.dataimportwidth=dataimportwidth;
    }

    public String getDataimportheight()
    {
        return dataimportheight;
    }

    public void setDataimportheight(String dataimportheight)
    {
        this.dataimportheight=dataimportheight;
    }

    public int doStartTag() throws JspException
    {
        return EVAL_BODY_BUFFERED;
    }

    public int doEndTag() throws JspException
    {
        if(ref==null||ref.trim().equals(""))
        {
            throw new JspException("必须指定<wx:dataimport/>的ref属性");
        }
        BodyContent bc=getBodyContent();
        String label=null;
        if(bc!=null) label=bc.getString();
        JspWriter out=pageContext.getOut();
        try
        {
            out.println(TagAssistant.getInstance().getDataImportDisplayValue(ref,dataimportwidth,dataimportheight,this.dataimportinitsize,
                    this.dataimportmaxbtn,this.dataimportminbtn,label,(HttpServletRequest)pageContext.getRequest()));
        }catch(IOException e)
        {
            log.error("显示数据导入标签到页面失败",e);
        }
        return EVAL_PAGE;
    }
}
